Skip to content

Use thread local dep graph encoding #139758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2025
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Apr 13, 2025

This adds thread local encoding of dep graph nodes. Each thread has a MemEncoder that gets flushed to the global FileEncoder when it exceeds 64 kB. Each thread also has a local cache of dep indices. This means there can now be empty gaps in SerializedDepGraph.

Indices are marked green and also allocated by the new atomic operation DepNodeColorMap::try_mark_green as the encoder lock is removed.

@rustbot
Copy link
Collaborator

rustbot commented Apr 13, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2025
@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 13, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 13, 2025
@bors
Copy link
Collaborator

bors commented Apr 13, 2025

⌛ Trying commit 8167fdb with merge 5545f9c...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2025
Use thread local dep graph encoding

This adds thread local encoding of dep graph nodes. Each thread has a `MemEncoder` that gets flushed to the global `FileEncoder` when it exceeds 64 kB. Each thread also has a local cache of dep indices. This means there can now be empty gaps in `SerializedDepGraph`.

Indices are marked green and also allocated by the new atomic operation `DepNodeColorMap::try_mark_green` as the encoder lock is removed.

This is based on rust-lang#139636 and rust-lang#139756.
@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 13, 2025

Local results, 1 thread, including #139756, excluding #139636:

BenchmarkBeforeAfterBeforeAfterBeforeAfter
TimeTime%Physical MemoryPhysical Memory%Committed MemoryCommitted Memory%
🟣 clap:check:unchanged0.3046s0.3076s 0.98%96.94 MiB98.15 MiB💔 1.24%168.25 MiB169.79 MiB 0.92%
🟣 hyper:check:unchanged0.1211s0.1221s 0.84%61.84 MiB62.02 MiB 0.29%125.11 MiB125.54 MiB 0.35%
🟣 regex:check:unchanged0.2250s0.2271s 0.92%78.13 MiB78.98 MiB💔 1.08%145.56 MiB146.65 MiB 0.75%
🟣 syn:check:unchanged0.4928s0.4971s 0.88%118.76 MiB120.38 MiB💔 1.36%193.57 MiB195.51 MiB💔 1.00%
Total1.1436s1.1540s 0.91%355.67 MiB359.52 MiB💔 1.08%632.49 MiB637.50 MiB 0.79%
Summary1.0000s1.0090s 0.90%1 byte1.01 bytes 0.99%1 byte1.01 bytes 0.75%

Local results, 7 threads, including #139756, excluding #139636:

BenchmarkBeforeAfterBeforeAfterBeforeAfter
TimeTime%Physical MemoryPhysical Memory%Committed MemoryCommitted Memory%
🟣 clap:check:unchanged0.3710s0.3140s💚 -15.37%133.25 MiB134.96 MiB💔 1.29%235.08 MiB237.04 MiB 0.83%
🟣 hyper:check:unchanged0.1466s0.1303s💚 -11.11%85.72 MiB86.31 MiB 0.69%191.98 MiB192.88 MiB 0.47%
🟣 regex:check:unchanged0.2831s0.2353s💚 -16.86%113.02 MiB114.25 MiB💔 1.09%212.53 MiB214.18 MiB 0.78%
🟣 syn:check:unchanged0.5756s0.5078s💚 -11.78%157.85 MiB160.31 MiB💔 1.56%260.80 MiB263.61 MiB💔 1.08%
Total1.3763s1.1875s💚 -13.72%489.84 MiB495.83 MiB💔 1.22%900.39 MiB907.70 MiB 0.81%
Summary1.0000s0.8622s💚 -13.78%1 byte1.01 bytes💔 1.16%1 byte1.01 bytes 0.79%

@bors
Copy link
Collaborator

bors commented Apr 13, 2025

☀️ Try build successful - checks-actions
Build commit: 5545f9c (5545f9c456a47860eda2f034f2d7636b31cff81c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5545f9c): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 16
Regressions ❌
(secondary)
0.5% [0.4%, 0.8%] 11
Improvements ✅
(primary)
-0.6% [-0.9%, -0.4%] 103
Improvements ✅
(secondary)
-0.6% [-1.0%, -0.3%] 24
All ❌✅ (primary) -0.4% [-0.9%, 0.5%] 119

Max RSS (memory usage)

Results (primary 1.8%, secondary 0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.8% [1.1%, 3.0%] 35
Regressions ❌
(secondary)
3.8% [2.2%, 9.2%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-5.1%, -2.3%] 7
All ❌✅ (primary) 1.8% [1.1%, 3.0%] 35

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 779.607s -> 782.154s (0.33%)
Artifact size: 365.51 MiB -> 365.50 MiB (-0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 13, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 14, 2025

r? compiler

@rustbot rustbot assigned Nadrieril and unassigned lcnr Apr 14, 2025
@Zoxc Zoxc force-pushed the thread-local-graph branch from 8167fdb to 7d236d0 Compare April 15, 2025 18:18
@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 16, 2025

I'd probably disregard the instruction improvements here and in #139756 as they don't translate into wall time improvements nor are they expected. Maybe MemEncoder uses less instructions?

I think the trade off towards the parallel compiler is reasonable here as incremental builds tends to have more free cores. Do note the 8.6% regression in dep graph size due to the added indices too.

#139756 is split out mostly to get a separate perf run and doesn't make sense without also merging this PR.

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned Nadrieril Apr 16, 2025
@Zoxc Zoxc marked this pull request as ready for review April 16, 2025 05:00
@bors
Copy link
Collaborator

bors commented Apr 17, 2025

☔ The latest upstream changes (presumably #139938) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -76,6 +80,9 @@ const DEP_NODE_PAD: usize = DEP_NODE_SIZE - 1;
const DEP_NODE_WIDTH_BITS: usize = DEP_NODE_SIZE / 2;

/// Data for use when recompiling the **current crate**.
///
/// There may be unused indices with DEP_KIND_NULL in this graph due to batch allocation of
/// indices to threads.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this batch allocation really necessary? Could we have a single atomic counter to assign the index and avoid the complexity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need at least 1 thread local allocation to avoid races when marking nodes green. A single counter would probably result in some congestion as promoting nodes is fairly hot too.

@Zoxc Zoxc force-pushed the thread-local-graph branch from 7d236d0 to c1067ba Compare April 22, 2025 02:44
@bors
Copy link
Collaborator

bors commented Apr 25, 2025

☔ The latest upstream changes (presumably #139756) made this pull request unmergeable. Please resolve the merge conflicts.

@Zoxc Zoxc force-pushed the thread-local-graph branch from c1067ba to 9bb8430 Compare April 25, 2025 23:46
@oli-obk
Copy link
Contributor

oli-obk commented May 6, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 6, 2025

📌 Commit e1e8857 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 6, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2025
Use thread local dep graph encoding

This adds thread local encoding of dep graph nodes. Each thread has a `MemEncoder` that gets flushed to the global `FileEncoder` when it exceeds 64 kB. Each thread also has a local cache of dep indices. This means there can now be empty gaps in `SerializedDepGraph`.

Indices are marked green and also allocated by the new atomic operation `DepNodeColorMap::try_mark_green` as the encoder lock is removed.
@bors
Copy link
Collaborator

bors commented May 6, 2025

⌛ Testing commit e1e8857 with merge 64d1378...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 6, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 6, 2025
@oli-obk
Copy link
Contributor

oli-obk commented May 6, 2025

Is the latest change related to the CI failure?

@Zoxc Zoxc force-pushed the thread-local-graph branch from 10096ce to cdd1049 Compare May 6, 2025 16:36
@Zoxc
Copy link
Contributor Author

Zoxc commented May 6, 2025

Yeah, but I changed it to use the portable AtomicU64 fallback now.

@oli-obk
Copy link
Contributor

oli-obk commented May 6, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 6, 2025

📌 Commit cdd1049 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 6, 2025
@bors
Copy link
Collaborator

bors commented May 7, 2025

⌛ Testing commit cdd1049 with merge 3ef8e64...

@bors
Copy link
Collaborator

bors commented May 7, 2025

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 3ef8e64 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 7, 2025
@bors bors merged commit 3ef8e64 into rust-lang:master May 7, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 7, 2025
Copy link

github-actions bot commented May 7, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing db0e836 (parent) -> 3ef8e64 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 3ef8e64ce9f72ee8d600d55bc43b36eed069b252 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 7408.3s -> 9319.7s (25.8%)
  2. dist-x86_64-apple: 9051.9s -> 11149.8s (23.2%)
  3. dist-aarch64-apple: 7024.6s -> 5794.5s (-17.5%)
  4. dist-arm-linux: 5257.9s -> 4400.3s (-16.3%)
  5. aarch64-apple: 4203.8s -> 4852.3s (15.4%)
  6. x86_64-gnu-llvm-20-3: 6815.5s -> 7341.1s (7.7%)
  7. x86_64-gnu-distcheck: 4386.0s -> 4724.3s (7.7%)
  8. x86_64-apple-2: 4662.4s -> 4950.9s (6.2%)
  9. dist-powerpc64le-linux: 9864.4s -> 9313.4s (-5.6%)
  10. dist-armhf-linux: 5120.7s -> 5399.4s (5.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3ef8e64): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.7%] 90
Regressions ❌
(secondary)
0.3% [0.2%, 0.5%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.7%] 90

Max RSS (memory usage)

Results (primary -0.6%, secondary -0.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.1% [0.4%, 1.9%] 2
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
-1.2% [-3.8%, -0.4%] 6
Improvements ✅
(secondary)
-4.8% [-4.8%, -4.8%] 1
All ❌✅ (primary) -0.6% [-3.8%, 1.9%] 8

Cycles

Results (primary 0.4%, secondary -4.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.4%, 0.8%] 15
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-0.6%, -0.4%] 3
Improvements ✅
(secondary)
-4.2% [-5.2%, -2.8%] 3
All ❌✅ (primary) 0.4% [-0.6%, 0.8%] 18

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 768.419s -> 770.356s (0.25%)
Artifact size: 365.16 MiB -> 365.20 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants